package main

import(
	"net/http"
	lg "github.com/cihub/seelog"
	"mylog"
)

type appError struct {
	XError error
	Message string
	Code int
}

func (e *appError) Error() string{
	return e.Message
}

type appHandler func(w http.ResponseWriter,r *http.Request) *appError

func (fn appHandler) ServerHTTP(w http.ResponseWriter,r *http.Request){
	if e:=fn(w,r);e!=nil{
		http.Error(w,e.Message,e.Code)
	}
}

func viewRecord(_ http.ResponseWriter,_ *http.Request) *appError{
	return &appError{nil,"error--->",403}
}

func main() {
	defer lg.Flush()

	mylog.Logger.Critical("server err:%v","错误")
	mylog.Logger.Info("发生。。。")

	http.HandleFunc("/admin",appHandler(viewRecord).ServerHTTP)
	http.ListenAndServe(":8111",nil)
}